<?php
if (!isset($GLOBALS['tagseditor'])) {
    ?>
    <link rel="stylesheet" href="./adminassets/tags/bootstrap-tokenfield.css">
    <link rel="stylesheet" href="./adminassets/tags/jquery-ui.min.css">
    <script charset="utf-8" src="./adminassets/tags/jquery-ui.min.js"></script>
    <script charset="utf-8" src="./adminassets/tags/bootstrap-tokenfield.js"></script>
    <?php
    $GLOBALS['tagseditor'] = 1;
}

//dump_pre($inputarray);
$cid = getGet('cid', 0);
$id = getGet('id', 0);
//echo $cid,$id,$inputname;
$tags = tag_find_postid($id, $inputname, $cid);
$tags_arr = array();
foreach ($tags as $row) {
    $tags_arr[] = $row['title'];
}
$alltags = tag_find_postcid(false, true);
$alltags_arr = array();
foreach ($alltags as $row) {
    $alltags_arr[] = $row['title'];
}
$alltags_arr = array_trim($alltags_arr);
$alltags_arr = array_flip($alltags_arr);
$alltags_arr = array_keys($alltags_arr);
$alltags_str = join(',', $alltags_arr);
$alltags_arr = explode(',', $alltags_str);

?>

<input type="text" class="form-control" id="tokenfield_<?php echo($inputname); ?>" name="<?php echo($inputname); ?>"
       value="<?= join(',', $tags_arr) ?>"/>
<script>
    $(function () {
        $('#tokenfield_<?php echo($inputname); ?>').tokenfield({
            autocomplete: {
                source: <?=json_encode($alltags_arr)?>,
                delay: 100
            },
            showAutocompleteOnFocus: true
        })
    })

</script>